package com.aayush.libs.generic_structures;

import java.util.ArrayList;
import java.util.List;

import android.util.Log;

/**
 * @author aayushjatrana@gmail.com
 */
public class JarvisStack<I> {
	private final String TAG = getClass().getSimpleName();
	private List<I> items;

	public JarvisStack() {
		items = new ArrayList<I>();
	}

	public I pop() {
		if (items.size() == 0) {
			Log.w(TAG, "Stack Underflow");
			return null;
		}
		I temp = items.get((items.size() - 1));
		items.remove(items.size() - 1);
		return temp;
	}

	public void push(I i) {
		items.add(i);
	}

	public I top() {
		return items.size() > 0 ? items.get(items.size() - 1) : null;
	}

	public List<I> toList() {
		return items;
	}
}
